js

您所在的位置:网站首页 notes 添加id js

js

#js| 来源: 网络整理| 查看: 265

{{ item.name }}

methods:

addId() { var data = document.querySelectorAll('.but .test'); // 选中所有的class为.but下面的.test的元素 // 遍历所有类名为.test的元素,为他们添加id data .forEach(function(v, i) { v.setAttribute('id', 'test-' + (i + 1)) }) },

得到的结果:

111.png


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3